define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'analyze/index' + location.search,
                    add_url: 'analyze/add',
                    edit_url: 'analyze/edit',
                    del_url: 'analyze/del',
                    multi_url: 'analyze/multi',
                    import_url: 'analyze/import',
                    table: 'analyze',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'country_ids', title: '国家'},
                        {field: 'admin.nickname', title: '管理员'},
                        {field: 'material_id', title: '素材类型'},
                        {field: 'click_num_10', title: '10分钟点击数'},
                        {field: 'complete_num_10', title: '10分钟进粉数'},
                        {field: 'total_click_num', title: '点击总数'},
                        {field: 'conversion_rate', title: '转化率'},
                        {field: 'r_1', title: '启用号码/总数'},
                        {field: 'extra_target_num', title: '剩余目标'},
                        {field: 'r_2', title: '完成/启用目标'},
                        {field: 'complete_time', title: '完成时间'},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
